<div class="box-news-view" id="item_history">{*
	<div class="box-slide">
			<div class="slide-mid">
				<div class="slide-title">Các tin bạn đã xem</div>
               
                <div>
                    <div class="slide-paging">Trang <b>1</b>/<b>3</b></div>
                    <div class="slide-content">
                        <div class="box-btn-slide-left">
                            <input type="button" onmouseout="this.className='btnSlideLeft'" onmouseover="this.className='btnSlideLeftOver'" name="btnSlideLeft" class="btnSlideLeft">
                        </div>
                        <div class="box-slide-content">
                            <div class="slide-img">
                            	<img class="element-del" src="style/images/list_del_hover.gif" width="13" height="13" title="Loại khỏi danh sách Tin đã xem"/>
                                <div class="box-slide-img" style="background:url(style/images201005/pic8.jpg) no-repeat center">
                                    <a href="#"><img src="style/images201005/space.gif" width="120" height="105"/></a>
                                </div>
                                <div class="box-slide-other">
                                    <div class="box-slide-other-title">
                                        <a href="#">Tắm cho bé sẽ dễ dàng hơn Tắm cho bé sẽ dễ dàng hơn</a>
                                    </div>
                                    <div class="box-slide-other-price">
                                        144.000.000.000 <img src="style/images201005/ico-vnd.gif" alt="VNĐ"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="box-btn-slide-right">
                            <input type="button" onmouseout="this.className='btnSlideRight'" onmouseover="this.className='btnSlideRightOver'" name="btnSlideRight" class="btnSlideRight">
                        </div>
                    </div>
                </div>
               
			</div>
		</div>
*}</div>
{literal}
<script>
recent_items = false;
cookie_data  = false;

jQuery(document).ready(function(){
	recent_items = jQuery.cookie('recent_items');
   
	if (recent_items){
		jQuery.post(WEB_DIR+"ajax.php?act=item&code=item_history",{
				itemids	: recent_items
			},
			function(json_data){
				cookie_data = json_data;
				show_item_history(1,1);
			},"json"
		); 
    }
});	
	
function show_his_page(page_show, page_hide){
	if(page_hide && page_show!=page_hide){
		jQuery("#his_page_" + page_show).show();
		jQuery("#his_page_" + page_hide).hide();		
	}
}

function show_item_history(show_page,rebuild){
	if(typeof(show_page) == 'undefined' || show_page == 1)
	show_page = 0;
	
	if(typeof(rebuild) == 'undefined')
	rebuild = 0;
	
	var re_items = '';
	
	if(cookie_data.length){
		var html_content = '';

		html_content = '<div class="box-slide"><div class="slide-mid"><div class="slide-title">Các tin bạn đã xem</div>';
		
		var page = 1;
		var gstt = 1;
		var max_page = Math.ceil(cookie_data.length/6);
		var new_page = 1;
		
		for (var i = 0; i < cookie_data.length; i++){
			if(rebuild){
				re_items += (re_items!=''?',':'') + '' + cookie_data[i].item_id + '';
			}
			
			if(new_page){
				new_page = 0;
				
				var page_pre = page - 1;
				if(i == 0){
					page_pre = max_page;
				}
				
				html_content +=  '<div id = "his_page_' + page +'" ' + (page>1?'style="display:none"':'') + '><div class="slide-paging">Trang <b>' + page +'</b>/<b>' + max_page + '</b></div><div class="slide-content"><div class="box-btn-slide-left"><input type="button" onmouseout="this.className=\'btnSlideLeft\'" onmouseover="this.className=\'btnSlideLeftOver\'" name="btnSlideLeft" class="btnSlideLeft" onclick="show_his_page(' + page_pre + ',' + page + ');"/></div><div class="box-slide-content">';
			}
			var price = "";
			
			if(cookie_data[i].price != "undefined" && cookie_data[i].price){
				price = cookie_data[i].price + ' <img src="style/images201005/ico-vnd.gif" alt="VNĐ"/>';
			}
			
			html_content += '<div class="slide-img" lang="'+ cookie_data[i].item_id +'"><img class="element-del" src="style/images/list_del_hover.gif" width="13" height="13" title="Loại khỏi danh sách Tin đã xem" id="ck_del_'+ cookie_data[i].item_id +'" onclick="ck_remove('+ cookie_data[i].item_id  + ',' + page + ');"/>\
							<div class="box-slide-img" '+ (cookie_data[i].item_image != ''? '' : 'style="background:url(style/images/no-images-69x53.jpg) no-repeat center') +'">\
								<a href="'+cookie_data[i].item_url+'"><img src="'+ (cookie_data[i].item_image != ''? cookie_data[i].item_image : 'style/images201005/space.gif' ) + '" class="lazyload" width="120" height="105"/></a>\
							</div>\
							<div class="box-slide-other">\
								<div class="box-slide-other-title">\
									<a href="'+cookie_data[i].item_url+'" title="'+cookie_data[i].item_title+'">'+cookie_data[i].item_title+'</a>\
								</div>\
								<div class="box-slide-other-price">\
									'+price+'\
								</div>\
							</div>\
						</div>';
				
		
			if(gstt == 6 || i == cookie_data.length-1){
				var page_next = page + 1;
				
				if(i == cookie_data.length-1){
					page_next = 1;
				}
				
				html_content += '</div>\
							<div class="box-btn-slide-right">\
								<input type="button" onmouseout="this.className=\'btnSlideRight\'" onmouseover="this.className=\'btnSlideRightOver\'" name="btnSlideRight" class="btnSlideRight" onclick="show_his_page(' + page_next + ',' + page + ');"/>\
							</div>\
						</div>\
					</div>';
					
				gstt = 1;
				page++;
				new_page = 1;
			}
			else{
				gstt++;	
			}
		}

		html_content += '</div>\
			</div>\
		</div><div style="clear:both"><span></span></div>';
		//alert (html_content);
		
		document.getElementById("item_history").innerHTML = html_content;
		document.getElementById("item_history").style.display = '';	
		
		
		jQuery(".slide-img").each(function() {
			jQuery(this).mouseover(function(){
				jQuery("#ck_del_" + this.lang).show();
											 });
			jQuery(this).mouseout(function(){
				jQuery("#ck_del_" + this.lang).hide();
											 });
		});
		
		
		if(show_page){
			jQuery("#his_page_" + 1).hide();
			jQuery("#his_page_" + show_page).show();
		}
		
		if(rebuild && re_items != recent_items){
			jQuery.cookie('recent_items', re_items, {path: '/', expires: 16});
		}
	}
}

function ck_remove(ck_id,page){
	 var cookie_ids = recent_items.split(",");
	 var stt 	= 0;
	 var tmp_ids = '';
	 
	 for (var i = 0; i <cookie_ids.length; i++){
	   if (!isNaN(cookie_ids[i]) && ck_id != cookie_ids[i] && stt < 35){
			var reid = parseInt(cookie_ids[i]);
			
			if(!isNaN(reid) &&  reid>0 && reid!=''){
				 tmp_ids += (tmp_ids!='' ? ',' : '') + parseInt(cookie_ids[i]);
				 stt++;
			}
		 }
	 }
	 
	if(stt && tmp_ids){
		recent_items = tmp_ids;
	 
		var tem_arr = [];
		stt = 0;
			 
		for(i=0; i<cookie_data.length; i++){
			if(cookie_data[i].item_id != ck_id){
				tem_arr[stt] = {"item_id":""+cookie_data[i].item_id+"","item_url":""+cookie_data[i].item_url+"","item_title":""+cookie_data[i].item_title+"","price":""+cookie_data[i].price+"","item_image":""+cookie_data[i].item_image+""};	
				stt++;
			}
		}
		
		if(stt){
			cookie_data = tem_arr;
			show_item_history(page);
		}
		else{
			recent_items = '';
		}
	}
	else{
		recent_items = '';
	}
	
	if (recent_items == ''){
		document.getElementById("item_history").style.display = 'none';	
	}
	
	// set cookie theo ngay
	jQuery.cookie('recent_items', recent_items, {path: '/', expires: 16});
}
</script>
{/literal}